home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-19 | 3.4 KB | 135 lines | [TEXT/MPS ] |
- ;
- ; Sound Asleep
- ; ©1992 David Thompson
- ;
- ; A little hack to audibly let the user know when the PowerBook is either going
- ; to sleep or waking up. There is also a C portion to this appliction.
- ;
- SEG 'Main'
- CASE OFF
- PRINT PUSH
- PRINT OFF
-
- INCLUDE 'PowerEqu.a'
- INCLUDE 'Traps.a'
-
- PRINT POP
-
- IMPORT playthatsound
- ;
- ; This is the Procedure called by the Power Manager to ask/tell the process that
- ; it's bedtime. This procedure is also called to wake up the process in case it
- ; wants to do something (like play a sound!).
- ;
- ; As part of the hack, this routine is also called by the C source to store the
- ; handles to the two sound resources in a space which is not A5 relative so that
- ; the procedure can execute even when it is not the current application.
- ;
-
- soundasleep PROC EXPORT
-
- StackFrame RECORD {A6Link},DECR
- ParamBegin EQU *
- ParamSize EQU ParamBegin-*
- RetAddr DS.L 1
- A6Link DS.L 1
- LocalSize EQU *
- ENDR
-
- WITH StackFrame
- LINK A6,#LocalSize
-
- CMPI.L #sleepRequest,D0 ; is this a network sleep request?
- BNE.S @1
- ; JSR RequestSleep ; we don't do anything special on network requests
- MOVE.L #0,D0 ; so we can always sleep (return 0 in D0)
- BRA.S Exit
-
- @1 CMPI.L #sleepDemand,D0 ; are we being told to go to sleep?
- BNE.S @2
- MOVE.L yawnHndl,-(A7)
- JSR playthatsound
- BRA.S Exit
-
- @2 CMPI.L #sleepWakeUp,D0 ; are we being told to wake up?
- BNE.S @3
- MOVE.L wakeHndl,-(A7)
- JSR playthatsound
- BRA.S Exit
-
- @3 CMPI.L #sleepRevoke,D0 ; is a network sleep request being cancelled?
- BNE.S sethandles
- ; JSR RevokeRequest ; since we don't do anything on a request, do nothing here too
- BRA.S Exit
-
- ; If we haven't been called with any of the above selectors, we're being called to
- ; store the Yawn and Wakeup sound handles. There is a static counter which is set
- ; to -1 initially. We see what value the counter is so we know which handle is
- ; being passed in D0.
-
- sethandles LEA counter,A0
- MOVE.L D1,-(SP)
- MOVE.W (A0),D1 ; save D1 on the stack because we use it
- CMPI.W #-1,D1 ; if counter is -1, save the yawn handle
- BEQ.S setyawn
- CMPI.W #0,D1 ; if counter is 0, save the wakeup handle
- BEQ.S setwake
- BRA.S restoreD1 ; otherwise, we're done (called by accident?)
- setyawn ADDQ.W #1,(A0)
- LEA yawnHndl,A0
- MOVE.L D0,(A0)
- BRA.S restoreD1
- setwake ADDQ.W #1,(A0)
- LEA wakeHndl,A0
- MOVE.L D0,(A0)
- restoreD1 MOVE.L (SP)+,D1 ; restore D1
-
- Exit UNLK A6
- MOVEA.L (SP)+,A0
- ADDA.L #ParamSize,SP
- JMP (A0)
-
- counter DC.W -1
- yawnHndl DC.L 0
- wakeHndl DC.L 0
-
- ENDP
- ;
- ; This routine is called from our C source to get the yawn and wake handles
- ; saved in some global variables that are accessable to the above procedure
- ; even if this Application isn't the current one.
- ;
- ; I had to call this routine because the above routine expected the handles
- ; passed in D0 and there was no easy way to do this from C without embedding
- ; some assembler in the C code (and I couldn't remember how to do this without
- ; the manuals).
- ;
-
- soundHandleSetup PROC EXPORT
-
- StackFrame1 RECORD {A6Link1},DECR
- ParamBegin1 EQU *
- YAWNARG DS.L 1
- WAKEARG DS.L 1
- ParamSize1 EQU ParamBegin1-*
- RetAddr1 DS.L 1
- A6Link1 DS.L 1
- LocalSize1 EQU *
- ENDR
-
- WITH StackFrame1
- LINK A6,#LocalSize1
-
- MOVE.L 12(SP),D0
- JSR soundasleep
- MOVE.L 8(SP),D0
- JSR soundasleep
- UNLK A6
- MOVEA.L (SP)+,A0
- ADDA.L #ParamSize1,SP
- JMP (A0)
-
- ENDP
-
- END
-